/*- coding = utf-8 -*-
@Time : 2023/4/2 10:56
@Author : 沉默小管
@File : useFunc.ts
@web  : golangblog.blog.csdn.net
@Software: WebStorm
*/

export const useFunc = (tableRef,emit,props)=>{

    /**
     * 设置滚动条到顶部的距离
     */
    const handleSetScrollTop = (topNum=0)=>{
        tableRef.setScrollTop(topNum)
    }
    /**
     * 清空选中的table
     */
    const handleClearSelection = ()=>{
        tableRef.clearSelection()
    }

    //修改当前页面条数
    const handleSizeChange = (val: number)=>{
        emit("handleSizeChange",val);
    }
    //修改当前页数
    const handleCurrentChange = (val: number) => {
        emit("handleCurrentChange",val);
    }

    //table中列表选中项
    const toggleRowSelection = (row: any)=>{
        tableRef.toggleRowSelection(row,true)
    }

    const handleGetHeight = ()=>{
        let topHeight = props.topHeight??0;//窗口顶层的高度
        let marginAndPaddingHeight = 25
        let pageHeight = !props.pageConfig.isPageShow?50:0;
        let fullHeight = document.documentElement.clientHeight+pageHeight;
        let otherHeight = props.tableConfig.topStyleClientHeight??document.querySelector(".top-style")?.clientHeight??0-0;//窗口中除了table其他的高度
        props.tableConfig.tableHeight=fullHeight-topHeight-otherHeight-marginAndPaddingHeight-topHeight
        window.addEventListener("resize",()=>{
            let topHeight = props.topHeight;//窗口顶层的高度
            let marginAndPaddingHeight = 25
            let fullHeight = document.documentElement.clientHeight+pageHeight;
            let otherHeight = props.tableConfig.topStyleClientHeight??document.querySelector(".top-style")?.clientHeight??0-0;//窗口中除了table其他的高度
            props.tableConfig.tableHeight=fullHeight-topHeight-otherHeight-marginAndPaddingHeight-topHeight
        })
    }
    return {
        handleSetScrollTop,handleClearSelection,handleSizeChange,handleCurrentChange,toggleRowSelection,handleGetHeight
    }
}